﻿using System;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Text;
using System.Web.UI;
using Common;
using CommonLib;
using DataAcl;
using HCRS.DBACL;
using HCRS.Implementation;
using HUBS1;
using Hubs1;
using JinJiang.BookingEngine.Services;
using Jinjiang.BLL;
using Email = Common.Email;

namespace JinJiang.BookingEngine.Web.en
{
    public partial class ResvDO : Page
    {
        QueryXml _QueryXmlClass = new QueryXml();
        DataAccessLayer _DataAccessLayer = new DataAccessLayer();
        Functions _Functions = new Functions();
        CommonWeb _CommonClass = new CommonWeb();
        HotelClass _HotelClass = new HotelClass();
        //UserClass _UserClass = new UserClass();
        Email _Email = new Email();
        public string paymentHtml;
        public string domain, domainurl;
        public static string emailfrom = System.Configuration.ConfigurationManager.AppSettings["emailfrom"].ToString();
        public static string emailalias = System.Configuration.ConfigurationManager.AppSettings["emailalias"].ToString();

        public string PageScript = "paystate = 1;";


        public string lblPayOrderNO = "";

        protected void Page_Load(object sender, EventArgs e)
        {

            if (Request.UrlReferrer != null)
                domain = FGBCommon.WebDomain(false, out domainurl);
            bodyBooking.Attributes.Add("onload", "fSetOutLinkIframe('" + domain + "')");

            if (!(IsPostBack))
            {
                PageScript = "paystate = 1;";

                btnPrintsuccess.Attributes.Add("onclick", "popprint('Reservation Info',document.getElementById('" + pnlSuccess.ClientID + "').innerHTML)");
                #region 定义变量
                string cardnumber = LoginInfo.Member != null ? LoginInfo.Member.UserId : string.Empty;
                pnlPrepay.Visible = false;

                int propertyid;
                bool showGuestInfo = true;
                bool foundhotel;
                string roomtype;
                string rateclass;
                string starttime;
                string deptime;

                string responsexml;
                string errmsg;
                int nights;
                int room;
                int adults;
                int children = 0;
                string verifycode = Request.QueryString["verifycode"] == null ? "" : Request.QueryString["verifycode"].ToString();

                string guestfirstname;
                string guestlastname;
                string guestemail;
                string guestphone;
                string guestMP;
                string guestaddressline1;
                string guestaddressline2;
                string guestcity;
                string guestcountry;
                string gueststate;
                string guestzip;
                string cctype;
                string ccnumber;
                string ccname;
                string ccexpyear;
                string ccexpmonth;
                string frequentguestid;
                string iata;
                string holdtime;
                string remarks;
                string confnum;
                string cxlnum;
                string status;
                string propertyname;
                string propertyname_e;
                string totalmount;
                string dailyprice;
                string userid;
                string plandesc;
                string roomname;
                string roomdesc;
                string canclerule;
                string guaranteerule;
                string incomingcall;
                string fromurl;
                int deleted;
                string SubSource;
                string lastuser;
                string lastusertype;
                string result;
                string taxRule;
                string payment;
                string billno;
                string currencyCode;
                string breakfast;
                DataTable errorDataTable;
                #endregion

                if (verifycode != "")
                {

                    try
                    {


                        _DataAccessLayer.addNewParameter("@verifycode", verifycode);

                        DataTable tableResv = _DataAccessLayer.RunStoreDataTable("FGB_JJ_ResvLog_Sel");

                        if (tableResv.Rows.Count != 0)
                        {

                            #region 变量 赋值
                            propertyid = Convert.ToInt32(tableResv.Rows[0]["propertyid"].ToString());
                            ////酒店图片 field 2007-11-16
                            //imgHotelInfo.Src = "getchkdata.aspx?hid="+new FITAjaxClass().getHotelID(propertyid);
                            ////===========================
                            roomtype = tableResv.Rows[0]["roomtype"].ToString();
                            rateclass = tableResv.Rows[0]["rateclass"].ToString();
                            userid = tableResv.Rows[0]["userid"].ToString();
                            starttime = Convert.ToDateTime(tableResv.Rows[0]["starttime"].ToString()).ToString("yyyy-MM-dd");
                            //deptime = tableResv.Rows[0]["deptime"].ToString();
                            deptime = Convert.ToDateTime(tableResv.Rows[0]["deptime"].ToString()).ToString("yyyy-MM-dd");
                            nights = Convert.ToInt32(tableResv.Rows[0]["nights"].ToString());
                            room = Convert.ToInt32(tableResv.Rows[0]["room"].ToString());
                            guestfirstname = tableResv.Rows[0]["guestfirstname"].ToString();
                            guestlastname = tableResv.Rows[0]["guestlastname"].ToString();
                            guestemail = tableResv.Rows[0]["guestemail"].ToString();
                            guestphone = tableResv.Rows[0]["guestphone"].ToString();
                            guestMP = tableResv.Rows[0]["guestMP"].ToString();
                            guestaddressline1 = tableResv.Rows[0]["guestaddressline1"].ToString();
                            guestaddressline2 = tableResv.Rows[0]["guestaddressline2"].ToString();
                            guestcity = tableResv.Rows[0]["guestcity"].ToString();
                            guestcountry = tableResv.Rows[0]["guestcountry"].ToString();
                            gueststate = tableResv.Rows[0]["gueststate"].ToString();
                            guestzip = tableResv.Rows[0]["guestzip"].ToString();
                            cctype = tableResv.Rows[0]["cctype"].ToString();
                            if (tableResv.Rows[0]["ccnumber"].ToString() != "")
                                ccnumber = HUBS1.CCEncrypt.Decrypto(tableResv.Rows[0]["ccnumber"].ToString());
                            else
                                ccnumber = "";
                            ccname = tableResv.Rows[0]["ccname"].ToString();
                            ccexpyear = tableResv.Rows[0]["ccexpyear"].ToString();
                            ccexpmonth = tableResv.Rows[0]["ccexpmonth"].ToString();
                            frequentguestid = tableResv.Rows[0]["frequentguestid"].ToString();
                            iata = tableResv.Rows[0]["iata"].ToString();
                            remarks = tableResv.Rows[0]["remarks"].ToString();
                            holdtime = Hubs1.ResvInfoUtil.GetResvInfoValue(tableResv.Rows[0]["ResvInfo"].ToString(), Hubs1.ResvInfoType.holdTime);

                            //_Email.SendMail("222", "New");

                            string specialXml = tableResv.Rows[0]["comment"].ToString();
                            //remarks += specialXml;
                            //Response.Write("<!-- "+specialXml+" -->");
                            confnum = tableResv.Rows[0]["confnum"].ToString();

                            //_Email.SendMail("confnum=" + confnum + ",vcode=" + verifycode, "New");

                            cxlnum = tableResv.Rows[0]["cxlnum"].ToString();
                            status = tableResv.Rows[0]["status"].ToString();
                            propertyname = tableResv.Rows[0]["propertyname"].ToString();
                            propertyname_e = tableResv.Rows[0]["propertyname_e"].ToString();
                            totalmount = tableResv.Rows[0]["totalmount"].ToString();
                            breakfast = tableResv.Rows[0]["breakfast"].ToString();
                            currencyCode = tableResv.Rows[0]["currencyCode"].ToString();
                            //   dailyprice = tableResv.Rows[0]["dailyprice"].ToString().Replace("|", "<br>");

                            string[] tempprice = tableResv.Rows[0]["dailyprice"].ToString().Split('|');
                            StringBuilder strPricelist = new StringBuilder();
                            StringBuilder strDate = new StringBuilder();
                            StringBuilder strPrice = new StringBuilder();

                            strPricelist.Append("<table   border=\"0\" cellpadding=\"0\" cellspacing=\"0\" > ");
                            for (int i = 1; i < tempprice.Length; i += 7)
                            {
                                strDate.Remove(0, strDate.Length);
                                strPrice.Remove(0, strPrice.Length);
                                strDate.Append("<tr align=\"center\"> ");
                                strPrice.Append("<tr align=\"center\">");
                                for (int c = 0; c < 7; c++)
                                {

                                    if ((i + c) < tempprice.Length)
                                    {
                                        strPrice.Append("<td class=\"td4\">");
                                        strDate.Append("<td class=\"td3\">");
                                        string[] temp = tempprice[i + c].Split(',');
                                        strDate.Append(temp[0]);
                                        strPrice.Append(temp[1]);

                                    }
                                    else
                                    {
                                        strPrice.Append("<td>");
                                        strDate.Append("<td>");

                                    }
                                    strPrice.Append("</td>");
                                    strDate.Append("</td>");

                                }
                                strPrice.Append("</tr>");
                                strDate.Append("</tr>");
                                strPricelist.Append(strDate);
                                strPricelist.Append(strPrice);
                            }

                            strPricelist.Append("</table> ");
                            dailyprice = strPricelist.ToString();

                            adults = Convert.ToInt32(tableResv.Rows[0]["adults"].ToString());
                            children = Convert.ToInt32(tableResv.Rows[0]["children"].ToString());

                            plandesc = tableResv.Rows[0]["planDesc"].ToString();
                            roomname = tableResv.Rows[0]["roomname"].ToString();
                            roomdesc = tableResv.Rows[0]["roomdesc"].ToString();
                            canclerule = tableResv.Rows[0]["canclerule"].ToString();
                            guaranteerule = tableResv.Rows[0]["guaranteerule"].ToString();
                            incomingcall = tableResv.Rows[0]["incomingcall"].ToString();
                            fromurl = tableResv.Rows[0]["fromurl"].ToString();
                            deleted = Convert.ToInt32(tableResv.Rows[0]["deleted"].ToString());

                            SubSource = tableResv.Rows[0]["SubSource"].ToString();
                            lastuser = tableResv.Rows[0]["lastuser"].ToString();

                            lastusertype = tableResv.Rows[0]["lastusertype"].ToString();


                            taxRule = tableResv.Rows[0]["taxRule"].ToString();
                            payment = tableResv.Rows[0]["payment"].ToString();

                            //_Email.SendMail("555", "New");

                            #endregion

                            bool reDO = false;

                            //_Email.SendMail("666", "New");

                            if (confnum != "")
                            {
                                reDO = true;

                                errmsg = "";

                                //_Email.SendMail("confnum != ''", "New");
                            }
                            else
                            {
                                //  errmsg = "";
                                ResvInfo resv = new ResvInfo();

                                resv.ratecode = rateclass;
                                resv.checkin = starttime;
                                resv.pid = propertyid;
                                resv.nights = nights;
                                resv.adults = adults;
                                resv.children = children;
                                resv.rooms = room;
                                resv.firstname = guestfirstname;
                                resv.lastname = guestlastname;
                                resv.guestaddressline1 = guestaddressline1;
                                resv.guestcity = guestcity;
                                resv.guestcountry = guestcountry;
                                resv.guestphone = guestphone;
                                resv.guestemail = guestemail;
                                resv.ccname = ccname;
                                resv.cctype = cctype;
                                resv.ccnumber = ccnumber;
                                resv.ccexpyear = ccexpyear;
                                resv.ccexpmonth = ccexpmonth;
                                resv.remark = remarks;
                                resv.from = "prestige.jinjianghotels.com/en";
                                resv.iata = iata;
                                resv.frequentguestid = frequentguestid;
                                resv.subsource = SubSource;
                                resv.specialxml = specialXml;

                                resv.roomcode = roomtype;
                                resv.gueststatecn = gueststate;
                                resv.guestzip = guestzip;
                                resv.holdtime = holdtime;
                                resv.mobile = guestMP;

                                string tempDates = "", tempPrices = "", tempCurrencyCode = "";

                                if (currencyCode == "")
                                {
                                    currencyCode = "CNY";
                                }

                                for (int i = 0; i < tempprice.Length; i++)
                                {
                                    if (tempprice[i].Length > 0)
                                    {
                                        tempDates += "," + tempprice[i].Split(',')[0];
                                        tempPrices += "," + tempprice[i].Split(',')[1];
                                        tempCurrencyCode += "," + currencyCode;
                                    }
                                }

                                tempDates = tempDates.Trim(new char[] { ',' });
                                tempPrices = tempPrices.Trim(new char[] { ',' });
                                tempCurrencyCode = tempCurrencyCode.Trim(new char[] { ',' });

                                resv.dates = tempDates.Split(',');
                                resv.prices = tempPrices.Split(',');
                                resv.currencycodes = tempCurrencyCode.Split(',');

                                //_Email.SendMail("555", "New");

                                //如果是积分税换，则在备注中怎加积分字样。
                                using (DataTable jjdt = _DataAccessLayer.GetTable("select * from jj_carduser_bookresv where verifycode='" + verifycode + "' and isscore=1", "dt"))
                                {
                                    //_Email.SendMail("积分税换", "New");

                                    if (jjdt.Rows.Count > 0)
                                    {
                                        //此单使用积分税换房间，传给FOG
                                        //_Email.SendMail("积分税换", "New");

                                        Loger.AddTextLog("Card Number:" + cardnumber + ",Confirm Number:" + confnum + ", exchanging with points");

                                        remarks += "<p>No service charge</p>";
                                    }
                                }

                                OrderClass.newresv(resv, out confnum, out status, out errmsg);

                                Loger.AddTextLog(errmsg + ", confnum=" + confnum + ",status=" + status);

                                //_Email.SendMail(errmsg + ", confnum=" + confnum + ",status=" + status, "New");

                                //lblPayOrderNO.Text = confnum;
                                lblPayOrderNO = confnum;

                            }

                            if (errmsg == "")
                            {

                                string strPayFrame = "<iframe id=\"payframe\" name=\"payframe\" src=\"#\" width=\"100%\" height=\"0\" frameborder=\"0\"" +
                                                    "scrolling=\"auto\" marginheight=\"0\" marginwidth=\"0\"></iframe>";

                                litHtml.Text = "";

                                //string strTargetFrame = "_blank";
                                string strTargetFrame = "payframe";

                                bool bPrePay = false;

                                if (!reDO)
                                {



                                    string[] ziduan = new string[2] { "confnum", "status" };
                                    string[] ziduanvalue = new string[2] { confnum, "New" };
                                    string filter = " verifycode='" + verifycode + "'";

                                    _DataAccessLayer.UpdateData("resvlog", ziduan, ziduanvalue, filter);
                                    CommonDataAccess.ExecUpdateSQL("jj_carduser_bookresv", "confnum", "nvarchar", new object[] { confnum }, "verifycode", "nvarchar", new object[] { verifycode });

                                    lblDesc.ForeColor = System.Drawing.Color.Green;
                                    #region 如果房型需要预付.
                                    if (payment == "PP")
                                    {
                                        Loger.AddTextLog("confnum=" + confnum + ", PP=" + payment);

                                        DateTime paytime = DateTime.Now;

                                        bPrePay = true;

                                        pnlSuccess.Visible = false;
                                        pnlFail.Visible = false;
                                        pnlPrepay.Visible = true;

                                        string payno = new DataAcl.ChinaPay().insertpaylog(confnum, totalmount, paytime);

                                        labpaytotal.Text = totalmount;
                                        string chkcode = DataAcl.Common.DESEncrypt("T:" + totalmount + ";C:" + confnum + ";D:" + paytime.ToString() + "P:" + payno, "epayanyd");

                                        string paystr = "<form method=\"post\" action=\"../pay/paybill.aspx\" target=\"" + strTargetFrame + "\"><input type=hidden ID=\"hidtotalmount\" name=\"hidtotalmount\" Value=\"" + totalmount + "\" />" +
                                        "<input type=hidden ID=\"hidpaytime\" name=\"hidpaytime\" value=\"" + paytime.ToString() + "\" />" +
                                        "<input type=hidden ID=\"hidverifycode\" name=\"hidverifycode\"  Value=\"" + confnum + "\" />" +
                                        "<input type=hidden ID=\"hidConfnum\" name=\"confnum\"  Value=\"" + confnum + "\" />" +
                                        "<input type=hidden ID=\"hidpayno\" name=\"hidpayno\"  Value=\"" + payno + "\" />" +
                                        "<input type=hidden id=\"chkcode\" name=\"chkcode\" value=\"" + chkcode + "\" />" +
                                        "<input type=submit ID=\"btnpay\" value=\"Pay now\" /><input type=\"button\" ID=\"btnpay2\" value=\"Pay now\" style='display:none;' disabled='true' /></form>";

                                        onlinepay.Text = paystr;

                                        litHtml.Text = strPayFrame;

                                        PageScript = "paystate = 0;";

                                        return;
                                    }
                                    else
                                    {
                                        this.lblDesc.Text = "<img src=\"images/ok.gif\" />Your reservation proccessed successfully。Confirmation number is <b><font color='#336699'>" + confnum + "</font></b>。Please keep this number。";
                                    }

                                    #endregion

                                }
                                else
                                {

                                    this.lblDesc.ForeColor = System.Drawing.Color.DarkSlateBlue;

                                    #region 预付

                                    if (payment == "PP")
                                    {
                                        DateTime paytime = DateTime.Now;
                                        string payno = "";
                                        bool payst = false;
                                        //totalmount = "0.01";

                                        string[] payStatus = _DataAccessLayer.RunSqlStrings("select billno,status,paytimebegin from pay where confnum='" + confnum + "'");

                                        if (payStatus != null)
                                        {
                                            if (payStatus[1].ToString() == "1" || payStatus[1].ToString() == "66")
                                            {
                                                //支付成功
                                                payst = true;
                                            }
                                            else
                                            {
                                                //未完成的支付
                                                paytime = Convert.ToDateTime(payStatus[2].ToString());
                                                payno = payStatus[0].ToString();

                                            }
                                        }

                                        pnlSuccess.Visible = false;
                                        pnlFail.Visible = false;
                                        pnlPrepay.Visible = true;

                                        bPrePay = true;

                                        //this.lblPrepay.Text = totalmount.ToString();
                                        labpaytotal.Text = totalmount;

                                        if (payst)
                                        {
                                            //labpayok.Text = "已经完成支付。";
                                            //labpayok.Visible = true;

                                            lblPayState.Text = "Pay successfully！";

                                            pnlPrepay.Visible = false;
                                            pnlSuccess.Visible = true; //Reservation Info可见

                                            this.lblDesc.Text = "<img src=\"images/ok.gif\" />Your reservation proccessed successfully。Confirmation number is <b><font color='#336699'>" + confnum + "</font></b>。Please keep this number。";

                                        }
                                        else
                                        {

                                            string chkcode = DataAcl.Common.DESEncrypt("T:" + totalmount + ";C:" + confnum + ";D:" + paytime.ToString() + "P:" + payno, "epayanyd");

                                            string paystr = "<form  method=\"post\" action=\"../pay/paybill.aspx\" target=\"" + strTargetFrame + "\">" +
                                                "<input type=hidden ID=\"hidtotalmount\" name=\"hidtotalmount\" Value=\"" + totalmount + "\" />" +
                                                "<input type=hidden ID=\"hidpaytime\" name=\"hidpaytime\" value=\"" + paytime.ToString() + "\" />" +
                                                "<input type=hidden ID=\"hidverifycode\" name=\"confnum\"  Value=\"" + confnum + "\" />" +
                                                "<input type=hidden ID=\"hidpayno\" name=\"hidpayno\"  Value=\"" + payno + "\" />" +
                                                "<input type=hidden id=\"chkcode\" name=\"chkcode\" value=\"" + chkcode + "\" />" +
                                                "<input type=submit ID=\"btnpay\" value=\"Pay now\" /><input type=\"button\" ID=\"btnpay2\" value=\"Pay now\" style='display:none;' disabled='true' /></form>";

                                            onlinepay.Text = paystr;

                                            litHtml.Text = strPayFrame;

                                            PageScript = "paystate = 0;";

                                            return;
                                        }

                                    }
                                    #endregion

                                    if (!bPrePay)
                                        this.lblDesc.Text = "<img src=\"images/warn.gif\" />This reservation was submitted, it cannot be submitted again。The confirmation number is " + confnum + "。Please keep this number。Please check the information below，We just sent a mail to your mailbox。";

                                }


                                string sql = "select Title,Title_e,Address1,Address1_e,phone,Checkin,Checkout,fop from hotel where pID=" + propertyid;
                                string[] Infos = _DataAccessLayer.RunSqlStrings(sql);


                                string title = Infos[0].ToString();
                                string title_e = Infos[1].ToString();
                                string address = Infos[2].ToString();
                                string address_e = Infos[3].ToString();
                                string phone = Infos[4].ToString();
                                string hCheckIN = DataAcl.Common.formatCheckInOut(Infos[5].ToString());
                                string hCheckOUT = DataAcl.Common.formatCheckInOut(Infos[6].ToString());
                                string fop = Infos[7].ToString();

                                pnlFail.Controls.Clear();

                                lblConfnum.Text = confnum;
                                if (status == "New")
                                {
                                    lblStatus.Text = "New reservation";
                                }
                                if (status == "mod")
                                {
                                    lblStatus.Text = "Modified reservation";
                                }
                                if (status == "cxl")
                                {
                                    lblStatus.Text = "Cancelled reservation";
                                }
                                lblHotelName.Text = title + " " + title_e;
                                lblHotelAddress.Text = address;
                                lblGuestName.Text = guestlastname + " " + guestfirstname;
                                lblCheckin.Text = starttime;
                                lblCheckout.Text = deptime;
                                lblNights.Text = nights.ToString();
                                lblPlanDesc.Text = plandesc;
                                lblRoomDesc.Text = roomdesc;
                                lblRoom.Text = room.ToString();
                                lblAdults.Text = adults.ToString();
                                lblChildren.Text = children.ToString();
                                lblPricelist.Text = dailyprice;


                                lblDailyPrice.Text = Convert.ToDouble(Convert.ToDouble(totalmount) / room / nights).ToString("#,##0.00");
                                lblTotalPrice.Text = totalmount;
                                lblCxlRule.Text = canclerule;
                                lblGuaRule.Text = guaranteerule;
                                lblEarlyChickin.Text = hCheckIN;
                                lblLateCheckin.Text = hCheckOUT;
                                lblRemark.Text = remarks;

                                bool bSend = true;

                                OnlinePay onpay = new OnlinePay();

                                if (bPrePay)
                                {


                                    int iPayState = onpay.GetPayState(confnum);

                                    if (iPayState == 1)
                                    {
                                        onpay.ChangePayState(confnum); //set pay = 1
                                    }

                                    bSend = !onpay.IsSent(confnum); //检查是否要发送邮件


                                }


                                if (bSend)
                                {
                                    if (bPrePay) onpay.SetSent(confnum); //设置发送标记

                                    if (_HotelClass.sendemailBookengine(confnum, "New", 1).Length == 0)
                                    {
                                        lblDesc.Text += "<br/><img src=\"images/ok.gif\" />Confirmation email has been sent。";
                                    }
                                    else
                                    {
                                        lblDesc.Text += "<br/><img src=\"images/warn.gif\" />Confirmation email sent failed。";
                                    }

                                    if (Request.QueryString["fax"] != null && Request.QueryString["fax"].Length > 0)
                                    {

                                        if (_HotelClass.sendfax(confnum, Request.QueryString["fax"].ToString(), "New").Length == 0)
                                        {
                                            lblDesc.Text += "<br/><img src=\"images/ok.gif\" />Confirmation fax has been sent。";
                                        }
                                        else
                                        {
                                            lblDesc.Text += "<br/><img src=\"images/warn.gif\" />Confirmation fax sent failed。";
                                        }
                                    }


                                    //发短信
                                    if (guestMP.Length > 0)
                                    {
                                        string smsContent = "Confirmation Number:" + confnum + "，" + title + room + " " + roomname + " has been confirmed，" + starttime + "(" + address + "，" + phone + ")";

                                        if (_Functions.SendSMS(smsContent, guestMP))
                                        {
                                            lblDesc.Text += "<br/><img src=\"images/ok.gif\" />Confirmation SMS message has been sent。";

                                        }
                                        else
                                        {
                                            lblDesc.Text += "<br/><img src=\"images/warn.gif\" />Confirmation SMS message sent failed。";
                                        }
                                    }
                                }



                                if (DataAcl.Common.checkexpojs(rateclass))
                                {
                                    googlejs.Text += "<script type=\"text/javascript\">\r\n";
                                    googlejs.Text += "var gaJsHost = ((\"https:\" == document.location.protocol) ? \"https://ssl.\" : \"http://www.\");\r\n";
                                    googlejs.Text += "document.write(unescape(\"%3Cscript src='\" + gaJsHost + \"google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E\"));\r\n";
                                    googlejs.Text += "</script>\r\n";
                                    googlejs.Text += "<script type=\"text/javascript\">\r\n";
                                    googlejs.Text += "try{\r\n";
                                    googlejs.Text += "var pageTracker = _gat._getTracker(\"UA-10768010-1\");\r\n";
                                    googlejs.Text += "pageTracker._trackPageview(\"/cn/booking_success\");\r\n";
                                    googlejs.Text += "} catch(err) {}</script>\r\n";
                                    googlejs.Text += "<script language=\"JavaScript\" type=\"text/javascript\">\r\n";
                                    googlejs.Text += "<!--\r\n";
                                    googlejs.Text += "var _gaext_OrderItems = new Array();\r\n";
                                    googlejs.Text += "_gaext_OrderItems[_gaext_OrderItems.length] = [\"c_rm\",\"i_ns\",\"f_pc\",\"c_cy\",\"c_dt\",\"c_tm\",\"i_pd\",\"c_cn\"];\r\n";
                                    googlejs.Text += "_gaext_OrderItems[_gaext_OrderItems.length] = [\"" + roomname + "\",\"" + nights.ToString() + "\",\"" + totalmount + "\",\" RMB \",\"" + DateTime.Now.ToString("yyyy-MM-dd") + "\",\"" + DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" + DateTime.Now.Second.ToString() + "\",\"" + propertyid.ToString() + "\",\"" + confnum + "\"];\r\n";
                                    googlejs.Text += "//-->\r\n";
                                    googlejs.Text += "</script>\r\n";
                                    googlejs.Text += "<script type=\"text/javascript\" language=\"JavaScript\">\r\n";
                                    googlejs.Text += "var gaExtJsHost = ((\"https:\" == document.location.protocol) ? \"https://\" : \"http://\");\r\n";
                                    googlejs.Text += "document.write(unescape(\"%3Cscript src='\" + gaExtJsHost + \"www.wwwtrac.com/js/ga_ext_track.js' type='text/javascript'%3E%3C/script%3E\"));\r\n";
                                    googlejs.Text += "document.write(unescape(\"%3Cscript src='\" + gaExtJsHost + \"www.wwwtrac.com/js/ga_ext.js' type='text/javascript'%3E%3C/script%3E\"));\r\n";
                                    googlejs.Text += "</script>\r\n";
                                    googlejs.Text += "<script type=\"text/javascript\" language=\"JavaScript\">\r\n";
                                    googlejs.Text += "<!--\r\n";
                                    googlejs.Text += "var ga_ext_track_cust_id = 2;\r\n";
                                    googlejs.Text += "var ga_ext_track_step_id = 1;\r\n";
                                    googlejs.Text += "var ga_ext_track_campaign_id = 1;\r\n";
                                    googlejs.Text += "ga_ext_track();\r\n";
                                    googlejs.Text += "//-->\r\n";
                                    googlejs.Text += "</script>\r\n";
                                }

                                if (rateclass.IndexOf("JJEXPO") >= 0)
                                {
                                    googlejs.Text += "<script type=\"text/javascript\">\r\n";
                                    googlejs.Text += "<!--\r\n";
                                    googlejs.Text += "var google_conversion_id = 1046185596;\r\n";
                                    googlejs.Text += "var google_conversion_language = \"en\";\r\n";
                                    googlejs.Text += "var google_conversion_format = \"2\";\r\n";
                                    googlejs.Text += "var google_conversion_color = \"ffffff\";\r\n";
                                    googlejs.Text += "var google_conversion_label = \"-zmtCNLZqgEQ_Izu8gM\";\r\n";
                                    googlejs.Text += "var google_conversion_value = 0;\r\n";
                                    googlejs.Text += "//-->\r\n";
                                    googlejs.Text += "</script>\r\n";
                                    googlejs.Text += "<script type=\"text/javascript\" src=\"http://www.googleadservices.com/pagead/conversion.js\">\r\n";
                                    googlejs.Text += "</script>\r\n";
                                    googlejs.Text += "<noscript>\r\n";
                                    googlejs.Text += "<div style=\"display:inline;\">\r\n";
                                    googlejs.Text += "<img height=\"1\" width=\"1\" style=\"border-style:none;\" alt=\"\" src=\"http://www.googleadservices.com/pagead/conversion/1046185596/?label=-zmtCNLZqgEQ_Izu8gM&amp;guid=ON&amp;script=0\"/>\r\n";
                                    googlejs.Text += "</div>\r\n";
                                    googlejs.Text += "</noscript>\r\n";
                                }
                            }
                            else
                            {
                                //_Email.SendMail("888", "New");

                                #region 撤销积分冻结
                                if (cardnumber.Length > 0)
                                {
                                    DataTable dt = DataAcl.ExecSql.GetDataSet("select * from jj_carduser_bookresv where verifycode='" + verifycode + "'").Tables[0];
                                    if (dt.Rows.Count > 0)
                                    {
                                        DataRow dr = dt.Rows[0];
                                        decimal scores = Convert.ToDecimal(dr["score"].ToString());
                                        string islockcode = dr["freezeno"].ToString();
                                        bool isexec = Convert.ToBoolean(dr["isexec"].ToString());
                                        bool islock = Convert.ToBoolean(dr["islock"].ToString());
                                        if (islock)
                                        {
                                            //锁定的积分需要解锁
                                            string errs = "";
                                            //if (!WestLake.LakeScore.unLockScore(islockcode, scores, cardnumber, out errs))
                                            //{
                                            //    //没有解锁成功

                                            //    Loger.AddTextLog("卡号:" + cardnumber + "解锁失败.");

                                            //    //CommonDataAccess.ExecUpdateSQL("jj_carduser_bookresv", "isexec", "bit", new object[] { true }, "verifycode", "nvarchar", new object[] { verifycode });
                                            //}
                                            //else
                                            //{
                                            //    //解锁成功

                                            //    //_Email.SendMail("卡号:" + cardnumber, "解锁积分成功！");

                                            //    Loger.AddTextLog("卡号:" + cardnumber + "解锁成功.");

                                            //    CommonDataAccess.ExecUpdateSQL("jj_carduser_bookresv", "islock", "bit", new object[] { false }, "verifycode", "nvarchar", new object[] { verifycode });
                                            //}
                                            Loger.AddTextLog("卡号:" + cardnumber + "解锁成功.");

                                            CommonDataAccess.ExecUpdateSQL("jj_carduser_bookresv", "islock", "bit", new object[] { false }, "verifycode", "nvarchar", new object[] { verifycode });

                                        }
                                    }
                                }

                                #endregion

                                pnlSuccess.Visible = false;
                                pnlFail.Visible = true;

                                lblErrMsg.Text = OrderClass.GetCrsError("newresv", "", "", "", errmsg);
                                lblErrMsg.Text += "<br>Please refresh the page and choose the other one!";

                                Loger.AddTextLog("CRS Error:" + cardnumber + lblErrMsg.Text);

                                //_Email.SendMail("订单失败:" + lblErrMsg.Text, "订单失败！");

                            }

                        }
                        else
                        {
                            pnlSuccess.Visible = false;
                            pnlFail.Visible = true;

                            lblErrMsg.Text = "<b> Input information error：</b><br>";
                            lblErrMsg.Text += "<br><img src=\"images/warn.gif\" />Cannot find the order，please retry！";

                            Loger.AddTextLog("SystemError:" + cardnumber + ",Cannot find the order，Please retry.");

                        }

                    }
                    catch (Exception eResv)
                    {
                        pnlSuccess.Visible = false;
                        pnlFail.Visible = true;


                        lblErrMsg.Text = "<b>Reservation failed：<b><br>" + eResv.ToString();
                        lblErrMsg.Text += "<br><img src=\"images/warn.gif\" />Error when create the order！";

                        Loger.AddTextLog("SystemError:" + cardnumber + "," + eResv.Message);

                        //_Email.SendMail(eResv.ToString(), "NewResv 预订未能成功");
                    }
                }
                else
                {
                    pnlSuccess.Visible = false;
                    pnlFail.Visible = true;

                    lblErrMsg.Text = "<b>Informaton error：<b><br>";
                    lblErrMsg.Text += "<br><img src=\"images/warn.gif\" /> Miss parameter!";

                    Loger.AddTextLog("SystemError:" + cardnumber + ", Miss parameter");
                }


            }
        }



        private void PrintOrder(DataTable tableResv)
        {
            #region
            int propertyid;
            bool showGuestInfo = true;
            bool foundhotel;
            string roomtype;
            string rateclass;
            string starttime;
            string deptime;

            string responsexml;
            string errmsg;
            int nights;
            int room;
            int adults;
            int children = 0;
            //string verifycode = Request.QueryString["verifycode"] == null ? "" : Request.QueryString["verifycode"].ToString();
            //Response.Write(verifycode);
            string guestfirstname;
            string guestlastname;
            string guestemail;
            string guestphone;
            string guestMP;
            string guestaddressline1;
            string guestaddressline2;
            string guestcity;
            string guestcountry;
            string gueststate;
            string guestzip;
            string cctype;
            string ccnumber;
            string ccname;
            string ccexpyear;
            string ccexpmonth;
            string frequentguestid;
            string iata;
            string remarks;
            string confnum;
            string cxlnum;
            string status;
            string propertyname;
            string propertyname_e;
            string totalmount;
            string dailyprice;
            string userid;
            string plandesc;
            string roomname;
            string roomdesc;
            string canclerule;
            string guaranteerule;
            string incomingcall;
            string fromurl;
            int deleted;
            string SubSource;
            string lastuser;
            string lastusertype;
            string result;
            string taxRule;
            string payment;
            string billno;
            propertyid = Convert.ToInt32(tableResv.Rows[0]["propertyid"].ToString());
            roomtype = tableResv.Rows[0]["roomtype"].ToString();
            rateclass = tableResv.Rows[0]["rateclass"].ToString();
            userid = tableResv.Rows[0]["userid"].ToString();
            starttime = Convert.ToDateTime(tableResv.Rows[0]["starttime"].ToString()).ToString("yyyy-MM-dd");
            //deptime = tableResv.Rows[0]["deptime"].ToString();
            deptime = Convert.ToDateTime(tableResv.Rows[0]["deptime"].ToString()).ToString("yyyy-MM-dd");
            nights = Convert.ToInt32(tableResv.Rows[0]["nights"].ToString());
            room = Convert.ToInt32(tableResv.Rows[0]["room"].ToString());
            guestfirstname = tableResv.Rows[0]["guestfirstname"].ToString();
            guestlastname = tableResv.Rows[0]["guestlastname"].ToString();
            guestemail = tableResv.Rows[0]["guestemail"].ToString();
            guestphone = tableResv.Rows[0]["guestphone"].ToString();
            guestMP = tableResv.Rows[0]["guestMP"].ToString();
            guestaddressline1 = tableResv.Rows[0]["guestaddressline1"].ToString();
            guestaddressline2 = tableResv.Rows[0]["guestaddressline2"].ToString();
            guestcity = tableResv.Rows[0]["guestcity"].ToString();
            guestcountry = tableResv.Rows[0]["guestcountry"].ToString();
            gueststate = tableResv.Rows[0]["gueststate"].ToString();
            guestzip = tableResv.Rows[0]["guestzip"].ToString();
            cctype = tableResv.Rows[0]["cctype"].ToString();
            if (tableResv.Rows[0]["ccnumber"].ToString() != "")
                ccnumber = HUBS1.CCEncrypt.Decrypto(tableResv.Rows[0]["ccnumber"].ToString());
            else
                ccnumber = "";
            ccname = tableResv.Rows[0]["ccname"].ToString();
            ccexpyear = tableResv.Rows[0]["ccexpyear"].ToString();
            ccexpmonth = tableResv.Rows[0]["ccexpmonth"].ToString();
            frequentguestid = tableResv.Rows[0]["frequentguestid"].ToString();
            iata = tableResv.Rows[0]["iata"].ToString();
            remarks = tableResv.Rows[0]["remarks"].ToString();
            confnum = tableResv.Rows[0]["confnum"].ToString();
            cxlnum = tableResv.Rows[0]["cxlnum"].ToString();
            status = tableResv.Rows[0]["status"].ToString();
            propertyname = tableResv.Rows[0]["propertyname"].ToString();
            propertyname_e = tableResv.Rows[0]["propertyname_e"].ToString();
            totalmount = tableResv.Rows[0]["totalmount"].ToString();
            dailyprice = tableResv.Rows[0]["dailyprice"].ToString().Replace("|", "<br>");
            adults = Convert.ToInt32(tableResv.Rows[0]["adults"].ToString());
            children = Convert.ToInt32(tableResv.Rows[0]["children"].ToString());
            plandesc = tableResv.Rows[0]["planDesc"].ToString();
            roomname = tableResv.Rows[0]["roomname"].ToString();
            roomdesc = tableResv.Rows[0]["roomdesc"].ToString();
            canclerule = tableResv.Rows[0]["canclerule"].ToString();
            guaranteerule = tableResv.Rows[0]["guaranteerule"].ToString();
            incomingcall = tableResv.Rows[0]["incomingcall"].ToString();
            fromurl = tableResv.Rows[0]["fromurl"].ToString();
            deleted = Convert.ToInt32(tableResv.Rows[0]["deleted"].ToString());
            SubSource = tableResv.Rows[0]["SubSource"].ToString();
            lastuser = tableResv.Rows[0]["lastuser"].ToString();
            lastusertype = tableResv.Rows[0]["lastusertype"].ToString();
            taxRule = tableResv.Rows[0]["taxRule"].ToString();
            payment = tableResv.Rows[0]["payment"].ToString();
            #endregion
            //页面付值:
            this.lblDesc.Text = "<img src=\"images/ok.gif\" />Reservation successfully。Confirmation number is <b><font color='#336699'>" + confnum + "</font></b>。请使用这个号码以备将来查询，并保留这个邮件作为您订房的凭证。。";

            string sql = "select Title,Title_e,Address1,Address1_e,phone,Checkin,Checkout,fop from hotel where pID=" + propertyid;
            string[] Infos = _DataAccessLayer.RunSqlStrings(sql);




            string title = Infos[0].ToString();
            string title_e = Infos[1].ToString();
            string address = Infos[2].ToString();
            string address_e = Infos[3].ToString();
            string phone = Infos[4].ToString();
            string hCheckIN = DataAcl.Common.formatCheckInOut(Infos[5].ToString());
            string hCheckOUT = DataAcl.Common.formatCheckInOut(Infos[6].ToString());
            string fop = Infos[7].ToString();

            //pnlSuccess.Visible = true;
            pnlFail.Controls.Clear();

            lblConfnum.Text = confnum;
            //lblConfnum1.Text = confnum;
            if (status == "New")
            {
                lblStatus.Text = "New reservation";
            }
            if (status == "mod")
            {
                lblStatus.Text = "Modified reservation";
            }
            if (status == "cxl")
            {
                lblStatus.Text = "Cancelled reservation";
            }
            lblHotelName.Text = title + " " + title_e;
            lblHotelAddress.Text = address;
            lblGuestName.Text = guestlastname + " " + guestfirstname;
            lblCheckin.Text = starttime;
            lblCheckout.Text = deptime;
            lblNights.Text = nights.ToString();
            lblPlanDesc.Text = plandesc;
            lblRoomDesc.Text = roomdesc;
            lblRoom.Text = room.ToString();
            lblAdults.Text = adults.ToString();
            lblChildren.Text = children.ToString();
            lblPricelist.Text = dailyprice;
            lblDailyPrice.Text = Convert.ToDouble(Convert.ToDouble(totalmount) / room / nights).ToString("#,##0.00");
            lblTotalPrice.Text = totalmount;
            lblCxlRule.Text = canclerule;
            lblGuaRule.Text = guaranteerule;
            lblEarlyChickin.Text = hCheckIN;
            lblLateCheckin.Text = hCheckOUT;
            lblRemark.Text = remarks;
        }

    }
}